using System.Collections;
using Wilco.SyntaxHighlighting.Engine.Scanner;

namespace Wilco.SyntaxHighlighting.Engine.Scanner
{
    /// <summary>
    /// Represents a collection of scanners.
    /// </summary>
    public class ScannerCollection : CollectionBase
    {
        /// <summary>
        /// Initializes a new instance of a <see cref="ScannerCollection"/> class.
        /// </summary>
        public ScannerCollection()
        {
            //
        }

        /// <summary>
        /// Gets an <see cref="IScanner"/> object at the specified index.
        /// </summary>
        public IScanner this[int index]
        {
            get
            {
                return (IScanner)List[index];
            }
        }

        /// <summary>
        /// Gets an <see cref="IScanner"/> object at the specified index.
        /// </summary>
        public IScanner this[string id]
        {
            get
            {
                for (int i = 0; i < Count; i++)
                    if (this[i].ID == id)
                        return this[i];
                return null;
            }
        }

        /// <summary>
        /// Adds a scanner.
        /// </summary>
        /// <param name="scanner">An <see cref="IScanner"/> object.</param>
        /// <returns>Index of the added object.</returns>
        public int Add(IScanner scanner)
        {
            return List.Add(scanner);
        }

        /// <summary>
        /// Removes a scanner.
        /// </summary>
        /// <param name="scanner">An <see cref="IScanner"/> object.</param>
        public void Remove(IScanner scanner)
        {
            List.Remove(scanner);
        }
    }
}